import BTAction from 'db://app-game/libs/math/behavior-tree/base/BTAction';
import { NodeStatus } from 'db://app-game/libs/math/behavior-tree/enum';
import { MoveModel, MoveRovToModelComp } from '../../ecs/base/bll/MoveRovToSystem';
import { Monster } from '../../ecs/biz/monster/Monster';
import { smc } from '../../ecs/singleton/SingletonModuleComp';

/** 怪兽向目标基地移动 */
export default class ActionMonsterMoveTo extends BTAction {
  onUpdate(monster: Monster): NodeStatus {
    console.log('ActionMonsterMoveTo——————怪兽向敌人移动');
    const lmat = monster.MonitorModelAttack;

    const move = monster.get(MoveRovToModelComp) || monster.add(MoveRovToModelComp);

    move.node = monster.MonsterView.node;
    move.map = smc.level.LevelMap.mapNode;
    move.speedOfMove = 100;
    move.offset = lmat.attackRange;
    move.target = lmat.lockTarget;

    // 设置流动网格移动
    move.moveModel = MoveModel.AStarMove;

    // 设置移动完成回调
    // move.onComplete = monster.attack.bind(monster);
    return NodeStatus.Success;
  }
}
